package com.xying.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import lombok.extern.slf4j.Slf4j;

/**
 * Created by Hisen on 2017/12/7.
 */
@Slf4j
public class EDcodingUtil {
  private static String DEFAULT_CHARSET = "UTF-8";

  public static String encodingURL(String value, String charset){
    try {
      value = URLEncoder.encode(value, charset);
    } catch (UnsupportedEncodingException e) {
      log.error("参数解码失败", e);
    }
    return value;
  }

  public static String decodingURL(String value, String charset){
    try {
      value = URLDecoder.decode(value, charset);
    } catch (UnsupportedEncodingException e) {
      log.error("参数解码失败", e);
    }
    return value;
  }

  public static String encodingURL(String value){
    try {
      value = URLEncoder.encode(value, DEFAULT_CHARSET);
    } catch (UnsupportedEncodingException e) {
      log.error("参数解码失败", e);
    }
    return value;
  }

  public static String decodingURL(String value){
    try {
      value = URLDecoder.decode(value, DEFAULT_CHARSET);
    } catch (UnsupportedEncodingException e) {
      log.error("参数解码失败", e);
    }
    return value;
  }
}
